package com.example.bzh.gamecat.httputils.newestutils;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;


import com.alibaba.fastjson.JSON;
import com.example.bzh.gamecat.bean.newest.DataBean;
import com.example.bzh.gamecat.util.OkHttpUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;


/**
 * Created by lenovo on 2016/7/30.
 */
public class DataModel {

    public static void getHomeData(final Context context, final String url, final Handler handler){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Log.i("TAG","url="+url);
                    String requestExe = OkHttpUtil.getRequestExe(url, context);
                    Log.i("TAG","requestExe="+requestExe);
                    JSONObject jsonObject = new JSONObject(requestExe);
                    JSONObject data = jsonObject.getJSONObject("data");
                    DataBean dataBean = JSON.parseObject(data.toString(), DataBean.class);
                    Log.i("TAG","dataBean="+dataBean.toString());
                    Message message = handler.obtainMessage(1,dataBean);
                    handler.sendMessage(message);

                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }).start();


    }
}
